package net.wanho.servlet;

import net.wanho.entity.User;
import net.wanho.service.UserService;
import net.wanho.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Author：汤小洋
 * Date：2025-09-03 14:57
 * Description：<描述>
 */
@WebServlet("/register")
public class RegisterServlet extends HttpServlet {

    private UserService userService = new UserServiceImpl();

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        /**
         * 获取参数并处理请求
         */
        req.setCharacterEncoding("utf-8");
        String name = req.getParameter("name");
        String phone = req.getParameter("phone");
        String address = req.getParameter("address");

        User user = new User();
        user.setName(name);
        user.setPhone(phone);
        user.setAddress(address);

        userService.register(user);

        /**
         * 响应
         */
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter out = resp.getWriter();
        out.print("<h2>注册成功</h2>");
        out.close();
    }
}
